#!/bin/sh
# PCP QA Test No. 1720
# Exercises pmdastatsd - agent's memory handling with Valgrind
#
# Copyright (c) 2020 Red Hat.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.python

test -e $PCP_PMDAS_DIR/statsd/pmdastatsd || _notrun "statsd PMDA not installed"

_check_valgrind

_cleanup()
{
    cd $here
    $sudo rm -rf $tmp $tmp.*

    # harvest results in case of failure
    #
    find $here/statsd/output -type f -print \
    | while read f
    do
	echo "--- $f ---" >>$here/$seq.full
	$sudo cat "$f" >>$here/$seq.full
	echo >>$here/$seq.full
	rm -f "$f"
    done
}

status=1	# failure is the default!
$sudo rm -rf $tmp $tmp.* $seq.full
$sudo rm -f $here/statsd/output/*
trap "_cleanup; exit \$status" 0 1 2 3 15

_prepare_pmda statsd
# note: _restore_auto_restart pmcd done in _cleanup_pmda()
trap "_cleanup_pmda statsd; _cleanup; exit \$status" 0 1 2 3 15
_stop_auto_restart pmcd

cd $here/statsd/src
test -d $here/statsd/output || mkdir $here/statsd/output
$sudo $python cases/15.py $here/statsd/output

cd $here
status=0
exit
